package com.codebattery.config;

import com.codebattery.domain.entity.Dict;
import com.codebattery.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.time.Duration;
import java.util.List;

@Component
public class InitConfig {

    @Autowired
    private DictService dictService;
    @Autowired
    ValueOperations<String, Object> valueOperations;

    @PostConstruct
    public void init(){
        System.out.println("服务启动初始化配置");

        List<Dict> allDicts = dictService.findAllDicts();
        for (Dict d : allDicts){
            valueOperations.set("Dict:" + d.getValue(), d);
        }

        return;
    }


}
